/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src;

import backend.Item;
import backend.Tag;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.thrift.TException;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;

/**
 *
 * @author chanhlt
 */
public class hellohandler extends AbstractHandler{

    @Override
    public void handle(String string, Request baseReq, HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
        res.setContentType("text/html; charset=utf-8");
        res.setStatus(HttpServletResponse.SC_OK);
        baseReq.setHandled(true);
        FrontendHandler handler=new FrontendHandler();
        Item item = null;
//        String n="1";
//        if(req.getParameter("n")!=null)
//        {
//             n=req.getParameter("n");
//        }
//        
//        List<String> listTag = null;
        try {
            //item=handler.getRandomItem();
            item=handler.getRandomItem();
            
        } catch (TException ex) {
            Logger.getLogger(hellohandler.class.getName()).log(Level.SEVERE, null, ex);
        }
        res.getWriter().println(item);
//        for(int i=0; i<listTag.size(); i++){
//            res.getWriter().println(listTag.get(i));
//        }
    }
    
}
